define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'layer'], function($, undefined, Frontend, Form, Template, Layer) {
    var validatoroptions = {
        invalid: function(form, errors) {
            $.each(errors, function(i, j) {
                Layer.msg(j);
            });
        }
    };
    var Controller = {
        index: function() {
            $('#alipay').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入新的支付宝',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'alipay',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         }  
                    })
                });
            })
            $('#wechatwallet').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入新的微信钱包',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'wechatwallet',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                    })
                    

                });
            });
            $('#nickname').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入新昵称',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'nickname',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                    })
                    

                });
            });
            $('#idcard').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入身份证号码',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'idcard',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                            
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                    })
                    

                });
            });
            $('#mobile').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入手机号码',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'mobile',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                    })
                    

                });
            });
            $('#email').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入邮箱编号',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'email',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                    })
                    

                });
            });
            $('#eth').on('click', function() {
                layer.prompt({
                    value: '',
                    title: '请输入USDT地址',
                    // area: ['800px', '350px'] //自定义文本域宽高
                }, function(value, index, elem) {
                    var index = layer.load();
                    $.post('user/profilesingle',{field:'eth',value:value},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           
                          }
                        });
                        if (rsp.code==0) {}else{
                           window.location.reload();
                         } 
                    })
                    

                });
            });
            $('#changepwd').on('click',function(){
                Layer.open({
                    type: 1,
                    content: Template('changepwdtpl',{}),
                    title:'修改登录密码',
                    btn: [__('修改')],
                    yes:function(index, layero){

                        var oldpassword = $("#oldpassword", layero).val()
                        var newpassword = $("#newpassword", layero).val()
                        var cnewpassword = $("#renewpassword", layero).val()
                        if (newpassword==''){
                            Layer.msg('新密码不能为空');
                            return false;
                        }
                        if(newpassword !== cnewpassword){
                            Layer.msg('验证密码不正确');
                            return false;
                        }
                        console.log(1)
                        $.post('user/changepwd',{
                            oldpassword:oldpassword,
                            newpassword:newpassword,
                            renewpassword:renewpassword,
                            _method: 'POST'
                        },function(data,json){
                            console.log(json)
                        });
                        console.log(2)
                        // Fast.api.ajax({
                        //     url:'user/changepwd',
                        //     data:{
                        //         oldpassword:oldpassword,
                        //         newpassword:newpassword,
                        //         renewpassword:renewpassword,
                        //         _method: 'POST'
                        //     }
                        // },function(data, ret){
                        //     console.log(data)
                        // },function(data, ret){
                        //     console.log(data)
                        // })
                    },
                    success:function(index, layero){
                    }
                });
            })


        },
        changepwd:function() {
           $("#changepwd").data("validator-options", validatoroptions);

              Form.api.bindevent($("#changepwd"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });
            $('#changeStyle').on('click',function(){
               $.post('/index/user/sendCode',{event:'resetpasswrod'},function(rsp){
                layer.closeAll();
                layer.msg(rsp.msg, {
                  offset: 'auto',
                  anim: 6,
                  end:function(){
                   
                  }
                });

               })
            });    
        },
        password:function() {
           $("#password").data("validator-options", validatoroptions);

              Form.api.bindevent($("#password"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });
            $('#changeStyle').on('click',function(){
               $.post('/index/user/sendCode',{event:'resetpaypasswrod'},function(rsp){
                layer.closeAll();
                layer.msg(rsp.msg, {
                  offset: 'auto',
                  anim: 6,
                  end:function(){
                   
                  }
                });

               })
            });  
        },
        bank_card_add:function(){
             $("#bank").data("validator-options", validatoroptions);

              Form.api.bindevent($("#bank"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });
        },
        bank_update:function(){
            $("#editbank").data("validator-options", validatoroptions);

              Form.api.bindevent($("#editbank"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });

            $('#delbank').on('click', function() {
                 var id=$('#infoid').val();
                
                 layer.open({
                    title: '是否确认删除',
                    yes: function(){
                     var index = layer.load();
                    $.post('user/delbank',{id:id},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                           window.location.href='http://'+window.location.host+'/index/user/getbanks.html';
                          }
                        });
                    })
                    }
                });

            });

        },
        editaddress:function(){
             $("#editaddress").data("validator-options", validatoroptions);

              Form.api.bindevent($("#editaddress"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });
              $('#deladdress').on('click', function() {
                 var id=$('#infoidaddress').val();
                 layer.open({
                    title: '是否确认删除',
                    yes: function(){
                     var index = layer.load();
                    $.post('user/deladdress',{id:id},function(rsp){
                        layer.closeAll();
                        layer.msg(rsp.msg, {
                          offset: 'auto',
                          anim: 6,
                          end:function(){
                            window.location.href='http://'+window.location.host+'/index/user/address.html'; 
                          }
                        });
                    })
                    }
                });

            });


        },
        address_add:function(){
            $("#address_add").data("validator-options", validatoroptions);

              Form.api.bindevent($("#address_add"), function (data, ret) {
                setTimeout(function () {
                    location.href = ret.url ? ret.url : "/";
                }, 1000);
              });
        },
        usdt:function(){
           $('#eth').on('click', function() {
              var value=$("#usdt").val();
              var captcha=$("#captcha").val();
              $.post('user/profilesingle',{field:'eth',value:value,captcha:captcha},function(rsp){
                  layer.closeAll();
                  layer.msg(rsp.msg, {
                    offset: 'auto',
                    anim: 6,
                    end:function(){
                     
                    }
                  });
                  if (rsp.code==0) {}else{
                     window.location.reload();
                   } 
              })
                    
            });
            $('#changeStyle').on('click',function(){
               $.post('/index/user/sendCode',{event:'USDT'},function(rsp){
                layer.closeAll();
                layer.msg(rsp.msg, {
                  offset: 'auto',
                  anim: 6,
                  end:function(){
                   
                  }
                });

               })
            });
        }
        
    };
    return Controller;
});